#include "GOTHcn.h"

void CN_InitCN(){
	/// @todo add other pin change interrupt enables
	USB_EnableOCD();

	// Global CN enable
	IFS1bits.CNIF = 0;
	IEC1bits.CNIE = 1;
	///@todo set CN interrupt priority
	//IPC4bits.CNIP =;
}

void __attribute__((interrupt,no_auto_psv)) _CNInterrupt(void){		
	
	/// @todo you can add application specific code for each CN event here
	if(PORTAbits.RA3 == 0){ // USB over-current detection
		UART_WriteBuffer((uint8 * )"USB Over-current.\n",18);
		UART_WriteBuffer((uint8 * )"Check your fuse.\n",17);
		USB_ToggleLed();
	}
	
	IFS1bits.CNIF = 0;		//Clear the interrupt flag
}
